#pragma once

#include <qbprotocol/include/SSMsgStruct.h>
#include <qbtools/message/MessagePoster.h>
#include <widgets/SPopupWindow.h>

#include <QFont>
#include <QLineEdit>
#include <QPaintEvent>
#include <QPushButton>
#include <QRect>
#include <QResizeEvent>
#include <QString>
#include <QStylePainter>

#include "core/ImageMgr.h"
#include "core/StyleMgr.h"

class CDlgAlterPassword : public SPopupWindow, public MessageReceiver {
  Q_OBJECT
 public:
  CDlgAlterPassword(QWidget* parent = nullptr);
  virtual ~CDlgAlterPassword();

 protected:
  void paintEvent(QPaintEvent* event) override;
  void onDataArrived(const qb::SSAckMsg& msg) override;

 signals:
  void modifySucceed(int errCode);
 protected slots:
  void onAckDataArrived(int errCode);

 protected:
  // 创建按钮
  void CreateButton();
  // 文本框
  void CreateEditCtrl(int w);
  void AlterPassword();
  // 显示错误信息
  void DisplayTipError(QString text);
  void ResponseAlterAccount(const qb::SSAckMsg& msg);
  void SetEnableBtn(bool bEnable);
  int SavePassword(std::string strPassword);
  int GetMaxWidth();
  int GetMaxHeight();
  void OnBtnOk();
  void OnBtnCancel();
  void resizeEvent(QResizeEvent* event);
  void DrawMain();

 private:
 protected:
  SImage* m_pimgBtnNormal;
  int m_nStaiticWidth;  // 静态字体宽度
  QString m_NewPass;    // 新密码
  QPushButton* m_btnOk;
  QPushButton* m_btnCancel;
  QLineEdit* arrEdit[3];
  QString m_strTip;
  QRect m_rcTip;
  QFont m_currentFont;  // 当前字体
  int m_fontSize;
  QRect rcEdit;
};
